﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNASequencing.core.Algorithms.rating
{
    class GaussRating : IRating
    {
        /// <summary>
        /// Number of all sequences.
        /// </summary>
        protected int _iSize;

        public GaussRating(int size)
        {
            _iSize = size;
        }

        double gaussFunction(double x, double phi, double sigma)
        {
            return Math.Exp(-Math.Pow(x - phi, 2) / (2 * Math.Pow(sigma, 2))) / (sigma * Math.Sqrt(2 * Math.PI));
        }

        double IRating.rate(Oligonucleotide o)
        {
            if (o.used)
                return 0;

            int followersNumber = 0;
            int l = o.originalSequence.Length;
            for (int i = 0; i < o.next.Length; ++i)
                    followersNumber += (o.originalSequence.Length - 1 - i) * o.next[i].Count;

            o.rating = 1 - gaussFunction(followersNumber, _iSize / 10.0, 1.0);
            o.rating *= (l - o.error) * Math.Sqrt(l);

            return o.rating;
        }
    }
}
